package com.cxz.kotlin.baselibs.ext

import android.widget.TextView
import androidx.core.content.res.ResourcesCompat


/**
 * 设置颜色直接使用colors.xml中定义的颜色即可
 */
fun TextView.setColor(resId: Int) {
    this.setTextColor(ResourcesCompat.getColor(this.context.resources, resId, null))
}

fun TextView.setDrawableLeft(resId: Int) {
    var drawable = ResourcesCompat.getDrawable(
        this.context.resources,
        resId,
        null
    )
    drawable?.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight)
    this.setCompoundDrawables(drawable, null, null, null)
}

fun TextView.setDrawableTop(resId: Int) {
    var drawable = ResourcesCompat.getDrawable(
        this.context.resources,
        resId,
        null
    )
    drawable?.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight)
    this.setCompoundDrawables(null, drawable, null, null)
}

fun TextView.setDrawableRight(resId: Int) {
    var drawable = ResourcesCompat.getDrawable(
        this.context.resources,
        resId,
        null
    )
    drawable?.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight)
    this.setCompoundDrawables(null, null, drawable, null)
}

fun TextView.setDrawableBottom(resId: Int) {
    var drawable = ResourcesCompat.getDrawable(
        this.context.resources,
        resId,
        null
    )
    drawable?.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight)
    this.setCompoundDrawables(null, null, null, drawable)
}